// var i;
// var $uI_Hall_UIBindings = require("./UI_Hall_UIBindings");
// var $bundleConfig = require("./BundleConfig");
// var $uIManager = require("./UIManager");
// var $uIView = require("./UIView");
// var $uIConfig_Home = require("./UIConfig_Home");
// var $eventManager = require("./EventManager");
// var $evenType = require("./EvenType");
// var $audioManager = require("./AudioManager");
// var $uIConfig_Game = require("./UIConfig_Game");
// var $playerDataManager = require("./PlayerDataManager");
// var $moduleManager = require("./ModuleManager");
// var $baseModule = require("./BaseModule");
// var $gameGlobalVariable = require("./GameGlobalVariable");
// var $const_Common = require("./Const_Common");
// var $guideControl = require("./GuideControl");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var $aIControl = require("./AIControl");
// var $redPointControl = require("./RedPointControl");
// var $gameDataManager = require("./GameDataManager");
// var $tipsManager = require("./TipsManager");
// var $resLoader = require("./ResLoader");
// var k = cc._decorator;
// var P = k.ccclass;
// var G = k.property;
// var D = k.inspector;
// var T = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t._dt = 0;
//         return t;
//     }
//     var o;
//     __extends(t, e);
//     o = t;
//     t.prototype._show = function () {
//         var e = this;
//         o._instance = this;
//         $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_Load_View, !1);
//         this.auto_ui.node_setting.active = !1;
//         this.auto_ui.setClickFast(this.auto_ui.btn_setting);
//         this.auto_ui.btn_sidebar.node.active = !1;
//         if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
//             mg.checkScene({
//                 scene: "sidebar",
//                 success: function (t) {
//                     e.auto_ui.btn_sidebar.node.active = t.isExist;
//                 }
//             });
//         }
//         $audioManager.AudioMgr.playMusic("sound/homebg", !0, $bundleConfig.BundleNames.Home);
//         this.ResetRichLabel();
//         $playerDataManager.PlayerDataMgr.getWuJinCount();
//         $hallGlobalVariable.default.selfMap["战斗按钮"] = this.auto_ui.btn_fightingBtn.node;
//         this.scheduleOnce(function () {
//             e.ifJiXuGame();
//         });
//         this.CheckUnLockFurit();
//         this.loadGame();
//     };
//     t.prototype.CheckUnLockFurit = function () {
//         var e = this;
//         var t = this;
//         var o = $playerDataManager.PlayerDataMgr.GameWinCheckUnlock();
//         if (o && o.length > 0) {
//             $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_UnlockNewEquip, {
//                 shuiGuoIds: o,
//                 callBack: function () {
//                     if (
//                         $playerDataManager.PlayerDataMgr.GetGuideIndexByTaskName($const_Common.GuideName.水果上阵) ==
//                         $const_Common.DressUpEquipGuideIndex.引导对话
//                     ) {
//                         var o = t.auto_ui.btn_wareHouseBtn.node;
//                         var n = o.convertToWorldSpaceAR(cc.v2(0, 0));
//                         var i = cc.size(o.width, o.height);
//                         var a = (e.node.height - 1334) / 2;
//                         $guideControl.GuideCtrl.ShowGuide({
//                             callBack: function () {
//                                 $playerDataManager.PlayerDataMgr.SetGuideIndex(
//                                     $const_Common.GuideName.水果上阵,
//                                     $const_Common.DressUpEquipGuideIndex.选择水果
//                                 );
//                                 t.ShowViewByType(1);
//                             },
//                             sayStr: "恭喜解锁了新水果，赶紧去将新水果上阵吧",
//                             wPos: n,
//                             size: i,
//                             sayNodePos: cc.v2(0, -250 - a)
//                         });
//                     } else {
//                         $aIControl.default._instance.ShowClickBtn(t.auto_ui.btn_wareHouseBtn.node, function () {
//                             t.ShowViewByType(1);
//                         });
//                     }
//                     $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.HallResetBag);
//                     $hallGlobalVariable.default.isNeedResetWareHouse = !0;
//                 }
//             });
//         } else {
//             if ($redPointControl.RedPointCtrl.GetRedPointByType($redPointControl.RedPointType.upEquip)) {
//                 $aIControl.default._instance.ShowClickBtn(t.auto_ui.btn_wareHouseBtn.node, function () {
//                     t.ShowViewByType(1);
//                 });
//             }
//         }
//         $hallGlobalVariable.default.selfMap["战斗按钮"] = this.auto_ui.btn_fightingBtn.node;
//     };
//     t.prototype.ifJiXuGame = function () {
//         if (
//             !(
//                 $playerDataManager.PlayerDataMgr.GetGuideIndexByTaskName($const_Common.GuideName.战斗背包) !=
//                     $const_Common.GameBagGuideIndex.引导完结 || $aIControl.default._instance.isOpen
//             )
//         ) {
//             if ($gameDataManager.GameDataMgr.getJiXuGame()) {
//                 $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_JiXuGame, 1);
//                 this.ShowViewByType(2);
//             }
//             $gameDataManager.GameDataMgr.getJiXuTiaoZhan()
//                 ? (this.ShowViewByType(3),
//                   $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_JiXuGame, 2))
//                 : -1 != $gameGlobalVariable.GameGlobalVariable.nowlevel
//                 ? this.ShowViewByType(2)
//                 : this.ShowViewByType(3);
//         }
//     };
//     t.prototype.start = function () {
//         var e = this;
//         this.scheduleOnce(function () {
//             if (
//                 $playerDataManager.PlayerDataMgr.GetGuideIndexByTaskName($const_Common.GuideName.仓库升级) ==
//                 $const_Common.UpEquipLevelGuideIndex.引导点击仓库水果2
//             ) {
//                 var t = e;
//                 var o = t.auto_ui.btn_wareHouseBtn.node;
//                 var n = o.convertToWorldSpaceAR(cc.v2(0, 0));
//                 var i = cc.size(o.width, o.height);
//                 var a = (e.node.height - 1334) / 2;
//                 $guideControl.GuideCtrl.ShowGuide({
//                     callBack: function () {
//                         t.ShowViewByType(1);
//                     },
//                     sayStr: "获得了水果碎片，去给水果升级提升战力吧",
//                     wPos: n,
//                     size: i,
//                     sayNodePos: cc.v2(0, -250 - a)
//                 });
//             }
//         });
//     };
//     t.prototype._addEventListener = function () {
//         this._addEvent($evenType.EVENT_TYPE.Game_count_down_time, this._refreshTime, this);
//         this._addEvent($evenType.EVENT_TYPE.Hall_ResetRich, this.ResetRichLabel, this);
//         this._addEvent($evenType.EVENT_TYPE.Hall_StartGame, this._start, this);
//         this._addEvent($evenType.EVENT_TYPE.GAME_TIAOZHAN_VIEW, this.openTeShuTiao, this);
//         this._addEvent($evenType.EVENT_TYPE.HallResetUnLockFurit, this.CheckUnLockFurit, this);
//     };
//     t.prototype._clickListener = function (e) {
//         var t = this.auto_ui;
//         switch (e) {
//             case t.btn_start:
//                 this._start();
//                 break;
//             case t.btn_choice:
//                 this._choice();
//                 break;
//             case t.btn_setting:
//                 this._setting();
//                 break;
//             case this.auto_ui.btn_sidebar:
//                 this._sidebar();
//                 break;
//             case this.auto_ui.btn_shopBtn:
//                 this.ShowViewByType(0);
//                 break;
//             case this.auto_ui.btn_wareHouseBtn:
//                 this.ShowViewByType(1);
//                 break;
//             case this.auto_ui.btn_fightingBtn:
//                 this.ShowViewByType(2);
//                 break;
//             case this.auto_ui.btn_newsBtn:
//                 this.ShowViewByType(3);
//                 break;
//             case this.auto_ui.btn_powerAddBtn:
//                 $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_AddPower);
//                 break;
//             case this.auto_ui.btn_goldAddBtn:
//                 this.ShowViewByType(0, {
//                     isBottom: !0
//                 });
//                 $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.HallScrollShop, {
//                     isBottom: !0
//                 });
//                 break;
//             case this.auto_ui.btn_diamondAddBtn:
//                 this.ShowViewByType(0, {
//                     isUp: !0
//                 });
//                 $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.HallScrollShop, {
//                     isUp: !0
//                 });
//         }
//     };
//     t.prototype._start = function (e, t) {
//         if (void 0 === e) {
//             e = 1;
//         }
//         if (void 0 === t) {
//             t = !1;
//         }
//         if (
//             $playerDataManager.PlayerDataMgr.globalData.power >=
//                 $gameGlobalVariable.GameGlobalVariable.kaishitilicount ||
//             t
//         ) {
//             t || $playerDataManager.PlayerDataMgr.SubPower($gameGlobalVariable.GameGlobalVariable.kaishitilicount);
//             $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_Load_View, !0);
//             this.onHideView();
//             $gameGlobalVariable.GameGlobalVariable.nowlevel = e;
//             $gameGlobalVariable.GameGlobalVariable.offtime = new Date().getTime();
//             $uIManager.default.open($bundleConfig.BundleNames.Game, $uIConfig_Game.UIView_Game.UI_GameView);
//         } else {
//             $tipsManager.TipMgr.showToast("体力不够");
//         }
//     };
//     t.prototype.openTeShuTiao = function () {
//         $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_Load_View, !0);
//         this.onHideView();
//         $gameGlobalVariable.GameGlobalVariable.teshulevel = 1;
//         $gameGlobalVariable.GameGlobalVariable.nowlevel = -1;
//         this._close();
//         $uIManager.default.open($bundleConfig.BundleNames.Game, $uIConfig_Game.UIView_Game.UI_GameView);
//     };
//     t.prototype.onHideView = function () {
//         $moduleManager.ModuleMgr.cleanModule();
//         this._close();
//     };
//     t.prototype._choice = function () {};
//     t.prototype._setting = function () {
//         this.auto_ui.node_setting.active = !this.auto_ui.node_setting.active;
//     };
//     t.prototype._sidebar = function () {
//         $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_Sidebar);
//     };
//     t.prototype.onResume = function (e) {
//         var t = [];
//         for (var o = 1; o < arguments.length; o++) {
//             t[o - 1] = arguments[o];
//         }
//         $audioManager.AudioMgr.playMusic("sound/homebgm", !0, $bundleConfig.BundleNames.Home);
//     };
//     t.prototype._refreshTime = function () {};
//     t.prototype.update = function () {};
//     t.prototype.ResetRichLabel = function () {
//         var e = this.auto_ui;
//         e.txt_powerLabel.string =
//             $playerDataManager.PlayerDataMgr.globalData.power +
//             "/" +
//             $playerDataManager.PlayerDataMgr.globalData.maxPower;
//         e.txt_goldLabel.string = "" + $playerDataManager.PlayerDataMgr.globalData.gold;
//         e.txt_diamondLabel.string = "" + $playerDataManager.PlayerDataMgr.globalData.diamond;
//     };
//     t.prototype.ShowViewByType = function (e, t) {
//         if (void 0 === t) {
//             t = {};
//         }
//         this.auto_ui.node_bottomBtnFather.children.forEach(function (t, o) {
//             t.children[1].active = o == e;
//             if (o == e) {
//                 t.width = t.children[1].width;
//                 t.height = t.children[1].height;
//             } else {
//                 t.width = t.children[0].width;
//                 t.height = t.children[0].height;
//             }
//         });
//         switch (e) {
//             case 0:
//                 $moduleManager.ModuleMgr.show($baseModule.ModuleNames.Shop, this.auto_ui.node_NewViewFather, t);
//                 break;
//             case 1:
//                 $moduleManager.ModuleMgr.show($baseModule.ModuleNames.WareHouse, this.auto_ui.node_NewViewFather, t);
//                 break;
//             case 2:
//                 $moduleManager.ModuleMgr.show($baseModule.ModuleNames.Fighting, this.auto_ui.node_NewViewFather, t);
//                 break;
//             case 3:
//                 $moduleManager.ModuleMgr.show($baseModule.ModuleNames.News, this.auto_ui.node_NewViewFather, t);
//         }
//     };
//     t.prototype.loadGame = function () {
//         $resLoader.default.loadBundle($bundleConfig.BundleNames.Game).then(function (e) {
//             console.log("Loaded main bundle", e);
//         });
//     };
//     __decorate([G($uI_Hall_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return (o = __decorate([P], t));
// })($uIView.default);
// exports.default = T;


// import AIControl from "./AIControl";
// import { AudioMgr } from "./AudioManager";
// import { ModuleNames } from "./BaseModule";
// import { BundleNames } from "./BundleConfig";
// import { DressUpEquipGuideIndex, GameBagGuideIndex, GuideName, UpEquipLevelGuideIndex } from "./Const_Common";
// import { EVENT_TYPE } from "./EvenType";
// import { EventMgrInstance } from "./EventManager";
// import { GameDataMgr } from "./GameDataManager";
// import { GameGlobalVariable } from "./GameGlobalVariable";
// import { GuideCtrlInstance } from "./GuideControl";
// import HallGlobalVariable from "./HallGlobalVariable";
// import { ModuleMgrInstance } from "./ModuleManager";
// import { PlayerDataMgr } from "./PlayerDataManager";
// import { RedPointCtrlInstance, RedPointType } from "./RedPointControl";
// import ResLoader from "./ResLoader";
// import { TipMgrInstance } from "./TipsManager";
// import { UIView_Game } from "./UIConfig_Game";
// import { UIView_Home } from "./UIConfig_Home";
// import UIManager from "./UIManager";
// import UIView from "./UIView";
// import UI_Hall_UIBindings from "./UI_Hall_UIBindings";

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * @class GameView
//  * 建议类名: HallViewHandler
//  */
// @ccclass
// class UI_Hall extends UIView {
//     @property(UI_Hall_UIBindings)
//     public auto_ui: UI_Hall_UIBindings = null!;
//     private _dt: number = 0;
//     public static _instance: UI_Hall;

//     /**
//      * 显示界面
//      * 建议方法名: showHall
//      */
//     protected _show(): void {
//         const self = this;
//         UI_Hall._instance = this;
//         EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_Load_View, false);
//         this.auto_ui.node_setting.active = false;
//         this.auto_ui.setClickFast(this.auto_ui.btn_setting);
//         this.auto_ui.btn_sidebar.node.active = false;

//         if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
//             // mg.checkScene({
//             //     scene: "sidebar",
//             //     success: function (t: any) {
//             //         self.auto_ui.btn_sidebar.node.active = t.isExist;
//             //     }
//             // });
//         }

//         AudioMgr.playMusic("sound/homebg", true, BundleNames.Home);
//         this.ResetRichLabel();
//         PlayerDataMgr.getWuJinCount();
//         HallGlobalVariable.selfMap["战斗按钮"] = this.auto_ui.btn_fightingBtn.node;
//         this.scheduleOnce(() => {
//             self.ifJiXuGame();
//         });
//         this.CheckUnLockFruit();
//         this.loadGame();
//     }

//     /**
//      * 检查解锁水果
//      * 建议方法名: checkUnlockFruit
//      */
//     private CheckUnLockFruit(): void {
//         const self = this;
//         const unlockItems = PlayerDataMgr.GameWinCheckUnlock();

//         if (unlockItems && unlockItems.length > 0) {
//             UIManager.open(BundleNames.Home, UIView_Home.UI_UnlockNewEquip, {
//                 shuiGuoIds: unlockItems,
//                 callBack: () => {
//                     if (PlayerDataMgr.GetGuideIndexByTaskName(GuideName.水果上阵) === DressUpEquipGuideIndex.引导对话) {
//                         const btnWarehouse = self.auto_ui.btn_wareHouseBtn.node;
//                         const worldPos = btnWarehouse.convertToWorldSpaceAR(cc.v2(0, 0));
//                         const size = cc.size(btnWarehouse.width, btnWarehouse.height);
//                         const offset = (self.node.height - 1334) / 2;

//                         GuideCtrlInstance.ShowGuide({
//                             callBack: () => {
//                                 PlayerDataMgr.SetGuideIndex(GuideName.水果上阵, DressUpEquipGuideIndex.选择水果);
//                                 self.ShowViewByType(1);
//                             },
//                             sayStr: "恭喜解锁了新水果，赶紧去将新水果上阵吧",
//                             wPos: worldPos,
//                             size: size,
//                             sayNodePos: cc.v2(0, -250 - offset)
//                         });
//                     } else {
//                         AIControl._instance.ShowClickBtn(self.auto_ui.btn_wareHouseBtn.node, () => {
//                             self.ShowViewByType(1);
//                         });
//                     }
//                     EventMgrInstance.dispatchEvent(EVENT_TYPE.HallResetBag);
//                     HallGlobalVariable.isNeedResetWareHouse = true;
//                 }
//             });
//         } else {
//             if (RedPointCtrlInstance.GetRedPointByType(RedPointType.upEquip)) {
//                 AIControl._instance.ShowClickBtn(self.auto_ui.btn_wareHouseBtn.node, () => {
//                     self.ShowViewByType(1);
//                 });
//             }
//         }
//         HallGlobalVariable.selfMap["战斗按钮"] = this.auto_ui.btn_fightingBtn.node;
//     }

//     /**
//      * 判断是否继续游戏
//      * 建议方法名: checkContinueGame
//      */
//     private ifJiXuGame(): void {
//         if (!(PlayerDataMgr.GetGuideIndexByTaskName(GuideName.战斗背包) !== GameBagGuideIndex.引导完结 || AIControl._instance.isOpen)) {
//             if (GameDataMgr.getJiXuGame()) {
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_JiXuGame, 1);
//                 this.ShowViewByType(2);
//             }
//             if (GameDataMgr.getJiXuTiaoZhan()) {
//                 this.ShowViewByType(3);
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_JiXuGame, 2);
//             } else if (GameGlobalVariable.nowlevel !== -1) {
//                 this.ShowViewByType(2);
//             } else {
//                 this.ShowViewByType(3);
//             }
//         }
//     }

//     /**
//      * 游戏启动
//      * 建议方法名: startGame
//      */
//     start(): void {
//         const self = this;
//         this.scheduleOnce(() => {
//             if (PlayerDataMgr.GetGuideIndexByTaskName(GuideName.仓库升级) === UpEquipLevelGuideIndex.引导点击仓库水果2) {
//                 const btnWarehouse = self.auto_ui.btn_wareHouseBtn.node;
//                 const worldPos = btnWarehouse.convertToWorldSpaceAR(cc.v2(0, 0));
//                 const size = cc.size(btnWarehouse.width, btnWarehouse.height);
//                 const offset = (self.node.height - 1334) / 2;

//                 GuideCtrlInstance.ShowGuide({
//                     callBack: () => {
//                         self.ShowViewByType(1);
//                     },
//                     sayStr: "获得了水果碎片，去给水果升级提升战力吧",
//                     wPos: worldPos,
//                     size: size,
//                     sayNodePos: cc.v2(0, -250 - offset)
//                 });
//             }
//         });
//     }

//     /**
//      * 添加事件监听器
//      * 建议方法名: addEventListeners
//      */
//     protected _addEventListener(): void {
//         this._addEvent(EVENT_TYPE.Game_count_down_time, this._refreshTime, this);
//         this._addEvent(EVENT_TYPE.Hall_ResetRich, this.ResetRichLabel, this);
//         this._addEvent(EVENT_TYPE.Hall_StartGame, this._start, this);
//         this._addEvent(EVENT_TYPE.GAME_TIAOZHAN_VIEW, this.openTeShuTiao, this);
//         this._addEvent(EVENT_TYPE.HallResetUnLockFurit, this.CheckUnLockFruit, this);
//     }

//     /**
//      * 处理点击事件
//      * @param e
//      * 建议方法名: handleClickEvent
//      */
//     protected _clickListener(e: cc.Button): void {
//         const autoUI = this.auto_ui;
//         switch (e) {
//             case autoUI.btn_start:
//                 this._start();
//                 break;
//             case autoUI.btn_choice:
//                 this._choice();
//                 break;
//             case autoUI.btn_setting:
//                 this._setting();
//                 break;
//             case autoUI.btn_sidebar:
//                 this._sidebar();
//                 break;
//             case autoUI.btn_shopBtn:
//                 this.ShowViewByType(0);
//                 break;
//             case autoUI.btn_wareHouseBtn:
//                 this.ShowViewByType(1);
//                 break;
//             case autoUI.btn_fightingBtn:
//                 this.ShowViewByType(2);
//                 break;
//             case autoUI.btn_newsBtn:
//                 this.ShowViewByType(3);
//                 break;
//             case autoUI.btn_powerAddBtn:
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_AddPower);
//                 break;
//             case autoUI.btn_goldAddBtn:
//                 this.ShowViewByType(0, { isBottom: true });
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.HallScrollShop, { isBottom: true });
//                 break;
//             case autoUI.btn_diamondAddBtn:
//                 this.ShowViewByType(0, { isUp: true });
//                 EventMgrInstance.dispatchEvent(EVENT_TYPE.HallScrollShop, { isUp: true });
//                 break;
//         }
//     }

//     /**
//      * 开始游戏
//      * @param level 等级
//      * @param skipPowerCheck 是否跳过体力检查
//      * 建议方法名: startGameAtLevel
//      */
//     private _start(level: number = 1, skipPowerCheck: boolean = false): void {
//         if (PlayerDataMgr.globalData.power >= GameGlobalVariable.kaishitilicount || skipPowerCheck) {
//             if (!skipPowerCheck) {
//                 PlayerDataMgr.SubPower(GameGlobalVariable.kaishitilicount);
//             }
//             EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_Load_View, true);
//             this.onHideView();
//             GameGlobalVariable.nowlevel = level;
//             GameGlobalVariable.offtime = new Date().getTime();
//             UIManager.open(BundleNames.Game, UIView_Game.UI_GameView);
//         } else {
//             TipMgrInstance.showToast("体力不够");
//         }
//     }

//     /**
//      * 打开特殊挑战
//      * 建议方法名: openSpecialChallenge
//      */
//     private openTeShuTiao(): void {
//         EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_Load_View, true);
//         this.onHideView();
//         GameGlobalVariable.teshulevel = 1;
//         GameGlobalVariable.nowlevel = -1;
//         this._close();
//         UIManager.open(BundleNames.Game, UIView_Game.UI_GameView);
//     }

//     /**
//      * 隐藏视图
//      * 建议方法名: hideView
//      */
//     private onHideView(): void {
//         ModuleMgrInstance.cleanModule();
//         this._close();
//     }

//     /**
//      * 用户选择处理
//      * 建议方法名: handleUserChoice
//      */
//     private _choice(): void { }

//     /**
//      * 设置界面处理
//      * 建议方法名: handleSettings
//      */
//     private _setting(): void {
//         this.auto_ui.node_setting.active = !this.auto_ui.node_setting.active;
//     }

//     /**
//      * 侧边栏处理
//      * 建议方法名: handleSidebar
//      */
//     private _sidebar(): void {
//         UIManager.open(BundleNames.Home, UIView_Home.UI_Sidebar);
//     }

//     /**
//      * 游戏恢复处理
//      * @param e
//      * 建议方法名: handleResume
//      */
//     onResume(e: any, ...args: any[]): void {
//         AudioMgr.playMusic("sound/homebgm", true, BundleNames.Home);
//     }

//     /**
//      * 刷新时间
//      * 建议方法名: refreshTime
//      */
//     private _refreshTime(): void { }

//     /**
//      * 更新处理
//      * 建议方法名: updateHandler
//      */
//     update(): void { }

//     /**
//      * 重置富文本标签
//      * 建议方法名: resetRichLabel
//      */
//     private ResetRichLabel(): void {
//         const autoUI = this.auto_ui;
//         autoUI.txt_powerLabel.string = `${PlayerDataMgr.globalData.power}/${PlayerDataMgr.globalData.maxPower}`;
//         autoUI.txt_goldLabel.string = `${PlayerDataMgr.globalData.gold}`;
//         autoUI.txt_diamondLabel.string = `${PlayerDataMgr.globalData.diamond}`;
//     }

//     /**
//      * 显示界面类型
//      * @param viewType 界面类型
//      * @param options 选项
//      * 建议方法名: showViewByType
//      */
//     public ShowViewByType(viewType: number, options: any = {}): void {
//         this.auto_ui.node_bottomBtnFather.children.forEach((child, index) => {
//             child.children[1].active = index === viewType;
//             if (index === viewType) {
//                 child.width = child.children[1].width;
//                 child.height = child.children[1].height;
//             } else {
//                 child.width = child.children[0].width;
//                 child.height = child.children[0].height;
//             }
//         });

//         switch (viewType) {
//             case 0:
//                 ModuleMgrInstance.show(ModuleNames.Shop, this.auto_ui.node_NewViewFather, options);
//                 break;
//             case 1:
//                 ModuleMgrInstance.show(ModuleNames.WareHouse, this.auto_ui.node_NewViewFather, options);
//                 break;
//             case 2:
//                 ModuleMgrInstance.show(ModuleNames.Fighting, this.auto_ui.node_NewViewFather, options);
//                 break;
//             case 3:
//                 ModuleMgrInstance.show(ModuleNames.News, this.auto_ui.node_NewViewFather, options);
//                 break;
//         }
//     }

//     /**
//      * 加载游戏资源
//      * 建议方法名: loadGameResources
//      */
//     private loadGame(): void {
//         ResLoader.loadBundle(BundleNames.Game).then((bundle) => {
//             console.log("Loaded main bundle", bundle);
//         });
//     }
// }

// export default UI_Hall;


import AICtrl from "./AIControl";
import { AudioMgr } from "./AudioManager";
import { ModuleNames } from "./BaseModule";
import { BundleNames } from "./BundleConfig";
import { DressUpEquipGuideIndex, GameBagGuideIndex, GuideName, UpEquipLevelGuideIndex } from "./Const_Common";
import { EVENT_TYPE } from "./EvenType";
import { EventMgrInstance } from "./EventManager";
import { GameDataMgr } from "./GameDataManager";
import { GameGlobalVariable } from "./GameGlobalVariable";
import { GuideCtrlInstance } from "./GuideControl";
import FruitDataManager from "./HallGlobalVariable";
import { ModuleMgr } from "./ModuleManager";
import { PlayerDataMgr } from "./PlayerDataManager";
import { RedPointCtrl, RedPointType } from "./RedPointControl";
import ResLoader from "./ResLoader";
import { TipMgr } from "./TipsManager";
import { UIView_Game } from "./UIConfig_Game";
import { UIView_Home } from "./UIConfig_Home";
import UIManager from "./UIManager";
import UIViewBase from "./UIView";
import UIHallUIBindings from "./UI_Hall_UIBindings";

const { ccclass, property, inspector } = cc._decorator;

/**
 * @class GameView
 * 建议类名: HallViewHandler
 */
@ccclass
class ViewHall extends UIViewBase {
    @property(UIHallUIBindings)
    public auto_ui: UIHallUIBindings = null!;
    private _deltaTime: number = 0;
    public static _instance: ViewHall;

    /**
     * 显示界面
     * 建议方法名: showHall
     */
    protected _show(): void {
        const that = this;
        ViewHall._instance = this;
        EventMgrInstance.emitEvent(EVENT_TYPE.Game_Load_View, false);
        this.auto_ui.node_setting.active = false;
        this.auto_ui.setClickFast(this.auto_ui.btn_setting);
        this.auto_ui.btn_sidebar.node.active = false;

        if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
            // mg.checkScene({
            //     scene: "sidebar",
            //     success: function (t: any) {
            //         that.auto_ui.btn_sidebar.node.active = t.isExist;
            //     }
            // });
        }

        AudioMgr.playBackgroundMusic("sound/homebg", true, BundleNames.Home);
        this.resetRichLabel();
        PlayerDataMgr.getWuJinCount();
        FruitDataManager.selfMap["战斗按钮"] = this.auto_ui.btn_fightingBtn.node;
        this.scheduleOnce(() => {
            that.checkContinueGame();
        });
        this.checkUnLockFruit();
        this.loadGame();
    }

    /**
     * 检查解锁水果
     * 建议方法名: checkUnlockFruit
     */
    private checkUnLockFruit(): void {
        const that = this;
        const unlockItems = PlayerDataMgr.gameWinCheckUnlock();

        if (unlockItems && unlockItems.length > 0) {
            UIManager.open(BundleNames.Home, UIView_Home.UI_UnlockNewEquip, {
                shuiGuoIds: unlockItems,
                callBack: () => {
                    if (PlayerDataMgr.getGuideIndexByTaskName(GuideName.FruitDressUpEquip) === DressUpEquipGuideIndex.GuideDialog) {
                        const btnWarehouse = that.auto_ui.btn_wareHouseBtn.node;
                        const worldPos = btnWarehouse.convertToWorldSpaceAR(cc.v2(0, 0));
                        const size = cc.size(btnWarehouse.width, btnWarehouse.height);
                        const offset = (that.node.height - 1334) / 2;

                        GuideCtrlInstance.showGuide({
                            callBack: () => {
                                PlayerDataMgr.setGuideIndex(GuideName.FruitDressUpEquip, DressUpEquipGuideIndex.SelectFruit);
                                that.showViewByType(1);
                            },
                            sayStr: "恭喜解锁了新水果，赶紧去将新水果上阵吧",
                            wPos: worldPos,
                            size: size,
                            sayNodePos: cc.v2(0, -250 - offset)
                        });
                    } else {
                        AICtrl._instance.displayClickButton(that.auto_ui.btn_wareHouseBtn.node, () => {
                            that.showViewByType(1);
                        });
                    }
                    EventMgrInstance.emitEvent(EVENT_TYPE.HallResetBag);
                    FruitDataManager.isNeedResetWareHouse = true;
                }
            });
        } else {
            if (RedPointCtrl.getRedPointStatusByType(RedPointType.upEquip)) {
                AICtrl._instance.displayClickButton(that.auto_ui.btn_wareHouseBtn.node, () => {
                    that.showViewByType(1);
                });
            }
        }
        FruitDataManager.selfMap["战斗按钮"] = this.auto_ui.btn_fightingBtn.node;
    }

    /**
     * 判断是否继续游戏
     * 建议方法名: checkContinueGame
     */
    private checkContinueGame(): void {
        if (!(PlayerDataMgr.getGuideIndexByTaskName(GuideName.GameBag) !== GameBagGuideIndex.GuideCompletion || AICtrl._instance.isOpen)) {
            if (GameDataMgr.getContinueGame()) {
                UIManager.open(BundleNames.Home, UIView_Home.UI_JiXuGame, 1);
                this.showViewByType(2);
            }
            if (GameDataMgr.getContinueChallenge()) {
                this.showViewByType(3);
                UIManager.open(BundleNames.Home, UIView_Home.UI_JiXuGame, 2);
            } else if (GameGlobalVariable.nowlevel !== -1) {
                this.showViewByType(2);
            } else {
                this.showViewByType(3);
            }
        }
    }

    /**
     * 游戏启动
     * 建议方法名: startGame
     */
    start(): void {
        const that = this;
        this.scheduleOnce(() => {
            if (PlayerDataMgr.getGuideIndexByTaskName(GuideName.EquipLevelUp) === UpEquipLevelGuideIndex.GuideClickWarehouseFruit2) {
                const btnWarehouse = that.auto_ui.btn_wareHouseBtn.node;
                const worldPos = btnWarehouse.convertToWorldSpaceAR(cc.v2(0, 0));
                const size = cc.size(btnWarehouse.width, btnWarehouse.height);
                const offset = (that.node.height - 1334) / 2;

                GuideCtrlInstance.showGuide({
                    callBack: () => {
                        that.showViewByType(1);
                    },
                    sayStr: "获得了水果碎片，去给水果升级提升战力吧",
                    wPos: worldPos,
                    size: size,
                    sayNodePos: cc.v2(0, -250 - offset)
                });
            }
        });
    }

    /**
     * 添加事件监听器
     * 建议方法名: addEventListeners
     */
    protected _addEventListener(): void {
        this._addEvent(EVENT_TYPE.Game_count_down_time, this._refreshTime, this);
        this._addEvent(EVENT_TYPE.Hall_ResetRich, this.resetRichLabel, this);
        this._addEvent(EVENT_TYPE.Hall_StartGame, this._start, this);
        this._addEvent(EVENT_TYPE.GAME_TIAOZHAN_VIEW, this.openSpecialChallenge, this);
        this._addEvent(EVENT_TYPE.HallResetUnLockFurit, this.checkUnLockFruit, this);
    }

    /**
     * 处理点击事件
     * @param e
     * 建议方法名: handleClickEvent
     */
    protected _clickListener(e: cc.Button): void {
        const autoUI = this.auto_ui;
        switch (e) {
            case autoUI.btn_start:
                this._start();
                break;
            case autoUI.btn_choice:
                this._choice();
                break;
            case autoUI.btn_setting:
                this._setting();
                break;
            case autoUI.btn_sidebar:
                this._sidebar();
                break;
            case autoUI.btn_shopBtn:
                this.showViewByType(0);
                break;
            case autoUI.btn_wareHouseBtn:
                this.showViewByType(1);
                break;
            case autoUI.btn_fightingBtn:
                this.showViewByType(2);
                break;
            case autoUI.btn_newsBtn:
                this.showViewByType(3);
                break;
            case autoUI.btn_powerAddBtn:
                UIManager.open(BundleNames.Home, UIView_Home.UI_AddPower);
                break;
            case autoUI.btn_goldAddBtn:
                this.showViewByType(0, { isBottom: true });
                EventMgrInstance.emitEvent(EVENT_TYPE.HallScrollShop, { isBottom: true });
                break;
            case autoUI.btn_diamondAddBtn:
                this.showViewByType(0, { isUp: true });
                EventMgrInstance.emitEvent(EVENT_TYPE.HallScrollShop, { isUp: true });
                break;
        }
    }

    /**
     * 开始游戏
     * @param level 等级
     * @param skipPowerCheck 是否跳过体力检查
     * 建议方法名: startGameAtLevel
     */
    private _start(level: number = 1, skipPowerCheck: boolean = false): void {
        if (PlayerDataMgr.globalData.power >= GameGlobalVariable.kaishitilicount || skipPowerCheck) {
            if (!skipPowerCheck) {
                PlayerDataMgr.subtractPower(GameGlobalVariable.kaishitilicount);
            }
            EventMgrInstance.emitEvent(EVENT_TYPE.Game_Load_View, true);
            this.onHideView();
            GameGlobalVariable.nowlevel = level;
            GameGlobalVariable.offtime = new Date().getTime();
            UIManager.open(BundleNames.Game, UIView_Game.UI_GameView);
        } else {
            TipMgr.showToast("体力不够");
        }
    }

    /**
     * 打开特殊挑战
     * 建议方法名: openSpecialChallenge
     */
    private openSpecialChallenge(): void {
        EventMgrInstance.emitEvent(EVENT_TYPE.Game_Load_View, true);
        this.onHideView();
        GameGlobalVariable.teshulevel = 1;
        GameGlobalVariable.nowlevel = -1;
        this._close();
        UIManager.open(BundleNames.Game, UIView_Game.UI_GameView);
    }

    /**
     * 隐藏视图
     * 建议方法名: hideView
     */
    private onHideView(): void {
        ModuleMgr.clearAllModules();
        this._close();
    }

    /**
     * 用户选择处理
     * 建议方法名: handleUserChoice
     */
    private _choice(): void { }

    /**
     * 设置界面处理
     * 建议方法名: handleSettings
     */
    private _setting(): void {
        this.auto_ui.node_setting.active = !this.auto_ui.node_setting.active;
    }

    /**
     * 侧边栏处理
     * 建议方法名: handleSidebar
     */
    private _sidebar(): void {
        UIManager.open(BundleNames.Home, UIView_Home.UI_Sidebar);
    }

    /**
     * 游戏恢复处理
     * @param e
     * 建议方法名: handleResume
     */
    onResume(e: any, ...args: any[]): void {
        AudioMgr.playBackgroundMusic("sound/homebgm", true, BundleNames.Home);
    }

    /**
     * 刷新时间
     * 建议方法名: refreshTime
     */
    private _refreshTime(): void { }

    /**
     * 更新处理
     * 建议方法名: updateHandler
     */
    update(): void { }

    /**
     * 重置富文本标签
     * 建议方法名: resetRichLabel
     */
    private resetRichLabel(): void {
        const autoUI = this.auto_ui;
        autoUI.txt_powerLabel.string = `${PlayerDataMgr.globalData.power}/${PlayerDataMgr.globalData.maxPower}`;
        autoUI.txt_goldLabel.string = `${PlayerDataMgr.globalData.gold}`;
        autoUI.txt_diamondLabel.string = `${PlayerDataMgr.globalData.diamond}`;
    }

    /**
     * 显示界面类型
     * @param viewType 界面类型
     * @param options 选项
     * 建议方法名: showViewByType
     */
    public showViewByType(viewType: number, options: any = {}): void {
        this.auto_ui.node_bottomBtnFather.children.forEach((child, index) => {
            child.children[1].active = index === viewType;
            if (index === viewType) {
                child.width = child.children[1].width;
                child.height = child.children[1].height;
            } else {
                child.width = child.children[0].width;
                child.height = child.children[0].height;
            }
        });

        switch (viewType) {
            case 0:
                ModuleMgr.show(ModuleNames.Shop, this.auto_ui.node_NewViewFather, options);
                break;
            case 1:
                ModuleMgr.show(ModuleNames.WareHouse, this.auto_ui.node_NewViewFather, options);
                break;
            case 2:
                ModuleMgr.show(ModuleNames.Fighting, this.auto_ui.node_NewViewFather, options);
                break;
            case 3:
                ModuleMgr.show(ModuleNames.News, this.auto_ui.node_NewViewFather, options);
                break;
        }
    }

    /**
     * 加载游戏资源
     * 建议方法名: loadGameResources
     */
    private loadGame(): void {
        ResLoader.loadBundle(BundleNames.Game).then((bundle) => {
            console.log("Loaded main bundle", bundle);
        });
    }
}

export default ViewHall;
